<template>
  <el-dialog
    :title="dialog.title"
    :visible.sync="dialog.visible"
    width="500px"
    append-to-body
  >
    <div class="dialog-box">
      <h3>导入失败</h3>
      <ul>
        <li v-for="(item, index) in dialog.data" :key="index">{{ item }}</li>
      </ul>
    </div>
    <div slot="footer" class="dialog-footer">
      <el-button type="primary" @click="submitForm">重新上传</el-button>
    </div>
  </el-dialog>
</template>

<script>
import { uploadFileSize } from "@/api/erecord/common";
export default {
  dicts: [],
  props: {
    dialog: {
      type: Object,
      default: {
        visible: false,
        title: "",
        data: [],
      },
    },
  },
  data() {
    return {
      buttonLoading: false,
      uploadFileSize: uploadFileSize(),
      // 表单参数
      form: {},
      // 表单校验
      rules: {},
    };
  },
  created() {
    this.reset();
  },
  methods: {
    importTemplate() {
      this.$emit("importTemplate");
    },
    // 表单重置
    reset() {
      this.form = {
        batchNo: undefined,
        processStatus: undefined,
        processMsg: undefined,
        attachMsg: undefined,
        remark: undefined,
        excelUrl: undefined,
        createTime: undefined,
        createBy: undefined,
        updateTime: undefined,
        updateBy: undefined,
        delFlag: undefined,
      };
      this.resetForm("form");
    },
    cancel() {
      const data = {
        visible: false,
        title: "",
      };
      this.$emit("update:dialog", data);
      this.buttonLoading = false;
      this.reset();
    },
    submitForm() {
      this.$refs["form"].validate((valid) => {
        if (valid) {
          if (!this.form.excelUrl) {
            this.$modal.msgError("请选择文件");
            return;
          }
          this.buttonLoading = true;
          this.$emit("importSubmit", this.form, () => {
            this.cancel();
          });
        }
      });
    },
  },
};
</script>
